package com.tz.dao;

import com.tz.entity.User;
import com.tz.util.HiberanteUtil;
import com.tz.util.MyThreadLocal;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;

/**
 * Created by Administrator on 15-6-29.
 */
@Repository //当前类是一个 Dao 组件
public class UserDaoImpl implements UserDao {

    private Session getSession(){
        System.out.println("从线程变量中取出session...");
        return MyThreadLocal.get();
    }

    public void save(User user) {
        getSession().save(user);
    }

    public User get(int id) {
        return  (User) getSession().get(User.class, id);
    }

    public void update(User user) {
        getSession().update(user);
    }
}
